#include "stdafx.h"

#include "DynLib.h"

typedef IPlugin* LoadPlugin();
typedef void UnloadPlugin();

IPlugin* CDynLib::Load()
{
    std::string strLibPath = "./";
    strLibPath += mstrName;
    mInst = (DYNLIB_HANDLE)DYNLIB_LOAD(strLibPath.c_str());
	
	if(mInst == NULL)
		return NULL;

	LoadPlugin *pFun = (LoadPlugin*)GetSymbol("LoadPlugin");	
	IPlugin *pPlugin = (*pFun)();

    return pPlugin;
}

bool CDynLib::UnLoad()
{
	if(mInst == NULL)
		return false;
	
	UnloadPlugin *pFun = (UnloadPlugin*)GetSymbol("UnloadPlugin");	
	(*pFun)();

    DYNLIB_UNLOAD(mInst);

    return true;
}

void* CDynLib::GetSymbol(const char* szProcName)
{
    return (DYNLIB_HANDLE)DYNLIB_GETSYM(mInst, szProcName);
}
